package GUI;
/**
 * principles approve/disapprove screen for student addtion to a course during the semester
 */

import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JButton;


import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;

public class PrincipleApprvStudentAdd extends JPanel {
	private JLabel lblNewLabel = null;
	private JComboBox exceptionalCb = null;
	private JButton btnApprove = null;
	private JButton btnDisapprove = null;
	private String rid = null;
	public Login myLoginFrame = null;
	public PrincipleMainMenu prmn = null;
	public UserPrinciple user = null;

	public  JComboBox getExceptionalCb(final PrincipleMainMenu prmn)
	{
		int i;
		Vector<String> data = new Vector<String>();
		for(i=0;i<prmn.user.dataExAddStudToCourse.size();i++)
		{
			data.add("Requesting student: "+prmn.user.dataExAddStudToCourse.get(i).StudName +" "+
					"Student ID: "+prmn.user.dataExAddStudToCourse.get(i).Sid +" "+
					"To course: "+prmn.user.dataExAddStudToCourse.get(i).CourseName+" "+
					"Course ID: "+prmn.user.dataExAddStudToCourse.get(i).Cid+" "+
					"From class: "+prmn.user.dataExAddStudToCourse.get(i).ClassId+" "+
					"Request number: "+prmn.user.dataExAddStudToCourse.get(i).Rid);
		}
		if(exceptionalCb==null)
		{
			
			exceptionalCb = new JComboBox(data);
			exceptionalCb.addActionListener(new ActionListener() {
				  public void actionPerformed(ActionEvent e) {
					rid=exceptionalCb.getSelectedItem().toString();
					String[] temp = rid.split(" ");
					
					prmn.user.setRid(temp[temp.length-1]);
					System.out.println("Alon"+rid);
					System.out.println(temp[temp.length-1]);
					
					
			 		//What happends when a user chooses a file in the CB
			 	}
			 });
			exceptionalCb.setBounds(100, 79, 600, 100);
			
		}
		return exceptionalCb;
	}
	
	
	public JButton getApproveBtn(final PrincipleMainMenu prmn)
	{
		if(btnApprove==null)
		{

			 btnApprove = new JButton("Approve");
			 btnApprove.addActionListener(new ActionListener() {
			 	public void actionPerformed(ActionEvent e) {
			 		
			 		user.DecisionUpdated=false;
			 		myLoginFrame.client.handleMessageFromClientUI("SetDesExReqAddStudToCourse "+prmn.user.getRid()+" true");
			 		while(!user.DecisionUpdated);
			 		
			 	}
			 });
			btnApprove.setForeground(new Color(34, 139, 34));
			btnApprove.setBounds(494, 320, 89, 23);
		}
		
		return btnApprove;
	}
	
	public JButton getDisApproveBtn(final PrincipleMainMenu prmn)
	{
		if(btnDisapprove==null)
		{

			btnDisapprove = new JButton("Disapprove");
			btnDisapprove.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					

			 		user.DecisionUpdated=false;
			 		myLoginFrame.client.handleMessageFromClientUI("SetDesExReqAddStudToCourse "+prmn.user.getRid()+" false");
			 		while(!user.DecisionUpdated);
				}
			});
			btnDisapprove.setForeground(Color.RED);
			btnDisapprove.setBounds(351, 320, 89, 23);
		}
		
		return btnDisapprove;
	}
	
	
	private void initialize(PrincipleMainMenu prmn)
	{
		setLayout(null);
		
		 lblNewLabel = new JLabel("Exception requests for students");
		lblNewLabel.setBounds(351, 11, 154, 14);
		add(lblNewLabel);
		
		
		add(getExceptionalCb(prmn));
		
		add(getApproveBtn(prmn));
		
		
		add(getDisApproveBtn(prmn));
	}
	
	public PrincipleApprvStudentAdd(PrincipleMainMenu prmn) {
		super();
		initialize(prmn);
		
	}
}
